package com.foxconn.AppDownload.util;

import com.foxconn.AppDownload.domain.ZxingLogoConfig;
import com.google.zxing.BarcodeFormat;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author zengdong
 * @version 1.0
 * @date 2023/12/20 10:19
 */
public class Utils {

    /**
     * 生成二维码图片
     * @param url   url链接
     * @param size      图片大小
     * @param logPath   app logo 位置
     * @param qrcodePath  二维码存放位置
     */
    public static void createQRCode(String url,int size, String logPath, String qrcodePath){
        ZXingCode zp =  ZXingCode.getInstance();
        BufferedImage bim = zp.getQRCODEBufferedImage(url, BarcodeFormat.QR_CODE, size, size,
                zp.getDecodeHintType());
        //ImageIO.write(bim, "png", response.getOutputStream());

        //如果是只要生成到本地文件夹 用以下写法
        File file=new File(qrcodePath);
        File logo=new File(logPath);
        BufferedImage aim = zp.addLogoQRCode(bim, logo, new ZxingLogoConfig());
        try {
            ImageIO.write(aim, "png", file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
